import java.util.ArrayList;


/**
 * @author ofer
 * This class handles HTTP GET requests.
 * TODO: handle HTTP POST requests. 
 */
public class HttpRequest {
	
	private String request_url = null;
	private ArrayList<Query> parm ;
	
	public HttpRequest(String url){
		this.request_url=url;
		parm = new ArrayList<Query>();
	}
	
	// parse request URL
	public ArrayList<Query> parse (){
		int i = this.request_url.indexOf('?');
		if (i>-1){
			String str = this.request_url.substring(i+1);
			String tmp = null;
			int j = str.indexOf('&');
			i=0;
			while (j>-1){
				tmp = str.substring(i, j);
				int k = tmp.indexOf('=');
				this.parm.add(new Query(tmp.substring(0,k) , tmp.substring(k+1) ) );
				i = j+1;
				j = str.indexOf('&', j+1);
			}
			tmp = str.substring(i);
			int k = tmp.indexOf('=');
			this.parm.add(new Query(tmp.substring(0,k-1) , tmp.substring(k+1) ) );
		}
		return(parm);
	}
	

}
